﻿// Copyright (C) 2009 Choonghwan Lee (linjus.lee@gmail.com)
//
// This file is part of amanda.
//
// amanda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// amanda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with amanda. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Reflection;
using System.Resources;

namespace manager
{
	/// <summary>
	/// Interaction logic for About.xaml
	/// </summary>
	public partial class About : Window
	{
		public About()
		{
			InitializeComponent();

			this.Title = String.Format("About {0}", AssemblyTitle);
			this.labelTitle.Content = AssemblyProduct;
			this.labelProductName.Content = AssemblyProduct;
			this.labelVersion.Content = String.Format("Version {0}", AssemblyVersion);
			this.labelCopyright.Content = AssemblyCopyright;
			this.listboxitemProductName.Content = AssemblyTitle;

			this.listboxCopyInfo.SelectedIndex = 0;
		}

		private void UpdateCopyrightInformation()
		{
			object o = this.listboxCopyInfo.SelectedValue;

			string msg = "";
			if (o == this.listboxitemProductName) {
				msg =
"Copyright (C) 2009 Choonghwan Lee (linjus.lee@gmail.com)\r\n" +
"\r\n" +
"amanda is free software: you can redistribute it and/or modify\r\n" +
"it under the terms of the GNU General Public License as published by\r\n" +
"the Free Software Foundation, either version 3 of the License, or\r\n" +
"(at your option) any later version.\r\n" +
"\r\n" +
"amanda is distributed in the hope that it will be useful,\r\n" +
"but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n" +
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n" +
"GNU General Public License for more details.\r\n" +
"\r\n" +
"You should have received a copy of the GNU General Public License\r\n" +
"along with amanda. If not, see <http://www.gnu.org/licenses/>.";
			}
			else if (o == this.listboxitemIcon) {
				msg =
"GNU General Public License version 2";
			}
			else if (o == this.listboxitemTagLib) {
				msg =
"TagLib# 2.0.3.2\r\n" +
"Copyright (C) 2006-2007 Brian Nickel\r\n" +
"\r\n" +
"This library is free software; you can redistribute it and/or modify\r\n" +
"it  under the terms of the GNU Lesser General Public License version\r\n" +
"2.1 as published by the Free Software Foundation.\r\n" +
"\r\n" +
"This library is distributed in the hope that it will be useful, but\r\n" +
"WITHOUT ANY WARRANTY; without even the implied warranty of\r\n" +
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r\n" +
"Lesser General Public License for more details.\r\n" +
"\r\n" +
"You should have received a copy of the GNU Lesser General Public\r\n" +
"License along with this library; if not, write to the Free Software\r\n" +
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307\r\n" +
"USA";
			}
			else if (o == this.listboxitemFlac) {
				msg =
"flac - Command-line FLAC encoder/decoder version 1.2.1\r\n" +
"Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007  Josh Coalson\r\n" +
"\r\n" +
"This program is free software; you can redistribute it and/or\r\n" +
"modify it under the terms of the GNU General Public License\r\n" +
"as published by the Free Software Foundation; either version 2\r\n" +
"of the License, or (at your option) any later version.\r\n" +
"\r\n" +
"This program is distributed in the hope that it will be useful,\r\n" +
"but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n" +
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n" +
"GNU General Public License for more details.\r\n" +
"\r\n" +
"You should have received a copy of the GNU General Public License\r\n" +
"along with this program; if not, write to the Free Software\r\n" +
"Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.";
			}
			else if (o == this.listboxitemOggDec) {
				msg =
				"OggDec\r\n" +
				"Copyright 2002, John Edwards\r\n" +
				"\r\n" +
				"This library is free software; you can redistribute it and/or\r\n" +
				"modify it under the terms of the GNU Library General Public\r\n" +
				"License as published by the Free Software Foundation; either\r\n" +
				"version 2 of the License, or (at your option) any later version.\r\n" +
				"\r\n" +
				"This library is distributed in the hope that it will be useful,\r\n" +
				"but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n" +
				"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU\r\n" +
				"Library General Public License for more details.\r\n" +
				"\r\n" +
				"You should have received a copy of the GNU Library General Public\r\n" +
				"License along with this library; if not, write to the\r\n" +
				"Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r\n" +
				"Boston, MA 02111-1307, USA.";
			}
			else if (o == this.listboxitemLame) {
				msg =
"LAME 32bits version 3.98.2 (http://www.mp3dev.org/)\r\n" +
"LGPL";
			}

			this.textboxCopyrightInfo.Text = msg;
		}

		#region Assembly Attribute Accessors

		public string AssemblyTitle
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
				if (attributes.Length > 0) {
					AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
					if (titleAttribute.Title != "") {
						return titleAttribute.Title;
					}
				}
				return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
			}
		}

		public string AssemblyVersion
		{
			get
			{
				return Assembly.GetExecutingAssembly().GetName().Version.ToString();
			}
		}

		public string AssemblyDescription
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
				if (attributes.Length == 0) {
					return "";
				}
				return ((AssemblyDescriptionAttribute)attributes[0]).Description;
			}
		}

		public string AssemblyProduct
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
				if (attributes.Length == 0) {
					return "";
				}
				return ((AssemblyProductAttribute)attributes[0]).Product;
			}
		}

		public string AssemblyCopyright
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
				if (attributes.Length == 0) {
					return "";
				}
				return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
			}
		}

		public string AssemblyCompany
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
				if (attributes.Length == 0) {
					return "";
				}
				return ((AssemblyCompanyAttribute)attributes[0]).Company;
			}
		}
		#endregion

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			this.Close();
		}

		private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			this.UpdateCopyrightInformation();
		}
	}
}
